Skip to content

Add RealisticExecutionModel: spread + slippage price adjustment#514

Open
jgianfelice wants to merge 9 commits intomementum:masterfrom
jgianfelice:master
Open

Add RealisticExecutionModel: spread + slippage price adjustment#514
jgianfelice wants to merge 9 commits intomementum:masterfrom
jgianfelice:master

Conversation

@jgianfelice
Copy link
Copy Markdown

@jgianfelice jgianfelice commented Mar 27, 2026

Problem

Backtrader assumes orders fill at the exact closing price, which overstates strategy performance by ignoring bid-ask spread and market slippage.

Solution

Adds 'backtrader/executionmodels/' as a new subpackage containing 'RealisticExecutionModel', which adjusts the actual fill price before the order is submitted.

Usage

from backtrader.executionmodels.realistic import RealisticExecutionModel

exec_model = RealisticExecutionModel(spread=0.0005, slippage=0.0005)
adj_price = exec_model.adjust_price(self.data.close[0], is_buy=True)
self.buy(size=100, price=adj_price, exectype=bt.Order.Limit)

Parameters

  • 'spread': half bid-ask spread as decimal (default: 5 bps)
  • 'slippage': adverse price movement on fill (default: 5 bps)

Example & Results

A full worked example with real benchmark results is available in the contributor's fork under:
github.com/jgianfelice/backtrader/tree/master/samples/execution-model-realistic

Running SPY with a simple SMA-20 crossover (2020-2024):

No costs: +8.46% return, Sharpe -0.50, Max DD 8.10%
With costs: +1.22% return, Sharpe -8.84, Max DD 1.23%
Cost drag: -7.24% return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant